package com.chance.cc.crawler.prod.command.job.domain.news.qimai;

import com.alibaba.fastjson.JSON;
import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.CrawlerJob;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.HttpPage;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.meta.core.bean.CrawlerMetaConstant;
import com.chance.cc.crawler.meta.core.bean.job.CrawlerScheduleJob;
import com.chance.cc.crawler.prod.command.job.domain.news.NewsCommonScript;
import org.apache.commons.lang3.StringUtils;

/**
 * @ClassName song
 * @Description TODO
 * @Author ding
 * @Date 2021/9/9 13:51
 * @Version 1.0\
 * 七麦评论采集
 **/
public class QimaiPublishCrawlerSchedulerJob extends NewsCommonScript {
    public static final String domain = "qimai";
    private static final String realtime = "realtime";
    public static void main(String[] args) {
        publishCrawlerScheduleJobInfo();
    }

    public static CrawlerJob publishCrawlerScheduleJobInfo(){

        CrawlerJob jdCrawlerJob = appStore();//苹果采集
     // CrawlerJob jdCrawlerJob = oppo();//oppo采集
    //    CrawlerJob jdCrawlerJob = huawei();//huawei采集
      //CrawlerJob jdCrawlerJob = mi();//mi采集
       //CrawlerJob jdCrawlerJob = vivo();//vivo采集
        //发布定时采集作业
        CrawlerScheduleJob crawlerScheduleJob = new CrawlerScheduleJob();
        crawlerScheduleJob.setDomain(domain);
        crawlerScheduleJob.setCrawlerJob(JSON.toJSONString(jdCrawlerJob));
        crawlerScheduleJob.setJobType(CrawlerMetaConstant.ScheduleCrawlerJobType.crawler.enumVal());
        crawlerScheduleJob.setNote("极氪001 苹果安卓定时采集 定时采集");
        crawlerScheduleJob.setCrawlerKey(jdCrawlerJob.generateCrawlerKey());
        HttpPage page = metaServiceCommand.addOrUpdateCrawlerScheduleJob(crawlerScheduleJob);
        System.out.println("发布作业：" + page.getRawText());
        return jdCrawlerJob;
    }

    /*
    * 苹果
    * */
    public static CrawlerJob appStore(){
        String site = "appStore";
        String site_bize = "geely";
        String site_info = site + "-" + realtime;
        String url = "https://www.qimai.cn/app/comment/appid/1570277888/country/cn";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .releaseTime(System.currentTimeMillis())
                .proxy(proxy)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1,null))
                .needParsed(true)
                .needWashed(false)
                .build();
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);
        record.tagsCreator().bizTags().addSiteBiz(site_bize);
        record.tagsCreator().bizTags().addCustomKV("site_info",site_info);

        return CrawlerJob.builder()
                .crawlerJobThreadNumber(10)
                .triggerInfo(
                        domain,
                        CrawlerMetaConstant.ScheduleJobTrigger_Cron,
                        System.currentTimeMillis(),//appStore-geely-realtime
                        StringUtils.joinWith("-",site,site_bize,CrawlerMetaConstant.ScheduleJobTriggerJob_Realtime))
                .crawlerRequestQueue(CrawlerMetaConstant.redisRequestQueue(StringUtils.joinWith("-","crawler",domain,site,site_bize,"queue")))
                .kafkaResultPipeline("kafka",kafkaTopic,null)
                .requestRecord(record)
                .build();
    }
    /*
     * oppo
     * */
    public static CrawlerJob oppo(){
        String site = "oppo";
        String site_bize = "geely";
        String site_info = site + "-" + realtime;
        String url = "https://www.qimai.cn/andapp/comment/appid/7797760/market/9";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .releaseTime(System.currentTimeMillis())
                .proxy(proxy)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1,null))
                .needParsed(true)
                .needWashed(false)
                .build();
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);
        record.tagsCreator().bizTags().addSiteBiz(site_bize);
        record.tagsCreator().bizTags().addCustomKV("site_info",site_info);

        return CrawlerJob.builder()
                .crawlerJobThreadNumber(10)
                .triggerInfo(
                        domain,
                        CrawlerMetaConstant.ScheduleJobTrigger_Cron,
                        System.currentTimeMillis(),//qimai-oppo-geely-realtime
                        StringUtils.joinWith("-",site,site_bize,CrawlerMetaConstant.ScheduleJobTriggerJob_Realtime))
                .crawlerRequestQueue(CrawlerMetaConstant.redisRequestQueue(StringUtils.joinWith("-","crawler",domain,site,site_bize,"queue")))
                .kafkaResultPipeline("kafka",kafkaTopic,null)
                .requestRecord(record)
                .build();
    }

    /*
     * 华为
     * */
    public static CrawlerJob huawei(){
        String site = "huawei";
        String site_bize = "geely";
        String site_info = site + "-" + realtime;
        String url = "https://www.qimai.cn/andapp/comment/appid/7797760/market/6";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .releaseTime(System.currentTimeMillis())
                .proxy(proxy)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1,null))
                .needParsed(true)
                .needWashed(false)
                .build();
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);
        record.tagsCreator().bizTags().addSiteBiz(site_bize);
        record.tagsCreator().bizTags().addCustomKV("site_info",site_info);

        return CrawlerJob.builder()
                .crawlerJobThreadNumber(10)
                .triggerInfo(
                        domain,
                        CrawlerMetaConstant.ScheduleJobTrigger_Cron,
                        System.currentTimeMillis(),//qimai-huawei-geely-realtime
                        StringUtils.joinWith("-",site,site_bize,CrawlerMetaConstant.ScheduleJobTriggerJob_Realtime))
                .crawlerRequestQueue(CrawlerMetaConstant.redisRequestQueue(StringUtils.joinWith("-","crawler",domain,site,site_bize,"queue")))
                .kafkaResultPipeline("kafka",kafkaTopic,null)
                .requestRecord(record)
                .build();
    }

    /*
     * 小米
     * */
    public static CrawlerJob mi(){
        String site = "mi";
        String site_bize = "geely";
        String site_info = site + "-" + realtime;
        String url = "https://www.qimai.cn/andapp/comment/appid/7797760/market/4";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .releaseTime(System.currentTimeMillis())
                .proxy(proxy)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1,null))
                .needParsed(true)
                .needWashed(false)
                .build();
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);
        record.tagsCreator().bizTags().addSiteBiz(site_bize);
        record.tagsCreator().bizTags().addCustomKV("site_info",site_info);

        return CrawlerJob.builder()
                .crawlerJobThreadNumber(10)
                .triggerInfo(
                        domain,
                        CrawlerMetaConstant.ScheduleJobTrigger_Cron,
                        System.currentTimeMillis(),//qimai-mi-geely-realtime
                        StringUtils.joinWith("-",site,site_bize,CrawlerMetaConstant.ScheduleJobTriggerJob_Realtime))
                .crawlerRequestQueue(CrawlerMetaConstant.redisRequestQueue(StringUtils.joinWith("-","crawler",domain,site,site_bize,"queue")))
                .kafkaResultPipeline("kafka",kafkaTopic,null)
                .requestRecord(record)
                .build();
    }

    /*
     * vivo
     * */
    public static CrawlerJob vivo(){
        String site = "vivo";
        String site_bize = "geely";
        String site_info = site + "-" + realtime;
        String url = "https://www.qimai.cn/andapp/comment/appid/7797760/market/8";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .releaseTime(System.currentTimeMillis())
                .proxy(proxy)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1,null))
                .needParsed(true)
                .needWashed(false)
                .build();
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);
        record.tagsCreator().bizTags().addSiteBiz(site_bize);
        record.tagsCreator().bizTags().addCustomKV("site_info",site_info);

        return CrawlerJob.builder()
                .crawlerJobThreadNumber(10)
                .triggerInfo(
                        domain,
                        CrawlerMetaConstant.ScheduleJobTrigger_Cron,
                        System.currentTimeMillis(),//oppo-oppo-realtime-realtime
                        StringUtils.joinWith("-",site,site_bize,CrawlerMetaConstant.ScheduleJobTriggerJob_Realtime))
                .crawlerRequestQueue(CrawlerMetaConstant.redisRequestQueue(StringUtils.joinWith("-","crawler",domain,site,site_bize,"queue")))
                .kafkaResultPipeline("kafka",kafkaTopic,null)
                .requestRecord(record)
                .build();
    }


}
